package com.example.demo.jenkins;

import com.example.demo.pojo.ModelFactory;
import com.offbytwo.jenkins.JenkinsServer;

import java.io.IOException;

public class ViewApi {

    // 连接Jenkins对象
    private JenkinsServer jenkinsServer;

    private ViewApi(){
        jenkinsServer = ModelFactory.INSTANCE.getJenkinsServer();
    }

    /**
     * 创建视图
     */
    private void createView() {
        try {
            // 创建一个 xml 字符串，里面设置一个 view 描述信息
            String xml = "<listView _class=\"hudson.model.ListView\">\n" +
                    "<description>用于测试的视图</description>\n" +
                    "</listView>";
            // 创建 view
            jenkinsServer.createView("test-view", xml);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public static void main(String[] args) {
        ViewApi viewApi = new ViewApi();
        viewApi.createView();
    }
}
